import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { WaitingGroupData } from "../copy/group/WaitingGroupData";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { SCopyGroupInfo } from "../../../../Message/Public/SCopyGroupInfo";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../com/mui/controls/GButton";
//class NearbyTeamListCellRenderer
    
    export  class NearbyTeamListCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */createChildren(): void
        {
            ObjCreate.createBg(0, 36, 328, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(180, 8, 60, 22, this, ImagesConst.DisabledBg);
            this._headImg = new Object /* flash.display.Bitmap */();
            this._headImg.width = 20;
            this._headImg.height = 20;
            this._headImg.x = 5;
            this._headImg.y = 7;
            this.addChild(this._headImg);
            this._nameLabel = ObjCreate.createLabel("", 25, 9, 120, 20, flash.text.TextFormatAlign.LEFT, this, false, 11661311);
            this._nameLabel.drawNow();
            this._levelLabel = ObjCreate.createLabel("", 113, 9, 42, 20, flash.text.TextFormatAlign.LEFT, this, false, 11661311);
            this._levelLabel.drawNow();
            this._numLabel = ObjCreate.createLabel("", 143, 9, 50, 20, flash.text.TextFormatAlign.LEFT, this, false, 16317633);
            this._numLabel.drawNow();
            this._progressLabel = ObjCreate.createLabel("", 180, 9, 62, 20, flash.text.TextFormatAlign.LEFT, this, false, 11661311);
            this._progressLabel.drawNow();
            this._joinBtn = ObjCreate.createGButton(Language.getString(62074), 250, 6, 70, 22, this);
            this._joinBtn.drawNow();
            this._joinBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onJoinBtnClick);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc2=null;
            var loc3=null;
            super.data = arg1;
            var loc1=arg1 as WaitingGroupData;
            if (loc1) 
            {
                this._isCross = loc1.isCross;
                loc2 = loc1.copy;
                if (loc3 = loc1.group) 
                {
                    this._nameLabel.htmlText = HTMLUtil.addColor(loc3.captainName, "#B1EFFE");
                    this._levelLabel.htmlText = HTMLUtil.addColor(loc3.captainLevel + "", "#B1EFFE");
                    this._numLabel.htmlText = HTMLUtil.addColor(loc3.playerNum + "/5", "#B1EFFE");
                    if (loc3.progress != -1) 
                    {
                        if (this._isCross) 
                        {
                            this._progressLabel.htmlText = HTMLUtil.addColor(Language.getString(60904), "#0BCAFE");
                        }
                        else 
                        {
                            this._progressLabel.htmlText = HTMLUtil.addColor(Language.getString(62076), "#0BCAFE") + HTMLUtil.addColor(loc3.progress + "/" + loc2.bossNum, "#FFFFFF");
                        }
                    }
                    else 
                    {
                        this._progressLabel.htmlText = HTMLUtil.addColor(Language.getString(62075), "#0BCAFE");
                    }
                    AvatarInfo.getAvatar(loc3.captainCamp, loc3.captainSex, AvatarType.SMALL, this.onAvatarLoaded, loc3.captainAvatarId);
                }
            }
            return;
        }

        /* internal  */onAvatarLoaded(arg1: ImageInfo): void
        {
            this._headImg.bitmapData = arg1.bitmapData;
            this._headImg.width = 22;
            this._headImg.height = 22;
            return;
        }

        /* internal  */onJoinBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=data["group"] as SCopyGroupInfo;
            if (this._isCross) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_DoApply, loc1.captainId));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Group_DoApply, loc1.captainId));
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        /* internal */ /* var */_isCross: Boolean;

        /* internal */ /* var */_headImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_levelLabel: GLabel;

        /* internal */ /* var */_numLabel: GLabel;

        /* internal */ /* var */_progressLabel: GLabel;

        /* internal */ /* var */_joinBtn: GButton;
    }
